//
//  CenterNewFriendVC.m
//  weibo
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CenterNewFriendVC.h"
#import "CenterNewFriendTableCell.h"
#import "AppDelegate.h"
#import "CenterNewFriendModel.h"

static NSString *const newFriendReuse = @"newFriendReuse";
//static NSString *const hot_countryReuse = @"hot_countryReuse";

@interface CenterNewFriendVC ()

@property (nonatomic, retain) UITableView *myTableView;

@end

@implementation CenterNewFriendVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.friendAllDicM = [NSMutableDictionary dictionary];
    self.friendNewArrayM = [NSMutableArray array];
    [self addNewFriendMassege];
    
    //创建TableView
    [self createView];
    
    
    // Do any additional setup after loading the view.
}

- (void)addNewFriendMassege
{
    AppDelegate *temp = [[UIApplication sharedApplication] delegate];
    NSMutableDictionary *friendNewDicM = [NSMutableDictionary dictionaryWithDictionary:temp.buddy];
    
    for (NSString *key in friendNewDicM) {
        CenterNewFriendModel *newFriendModel = [[CenterNewFriendModel alloc] init];
        newFriendModel.userName = key;
        newFriendModel.massege = [friendNewDicM objectForKey:key];
        [self.friendNewArrayM addObject:newFriendModel];
    }
    
//    NSLog(@"self.friendNewDicM=========%@",self.friendNewDicM);

}


- (void)createView {
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64) style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    self.myTableView.backgroundColor = [UIColor whiteColor];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;

    UINib *nib = [UINib nibWithNibName:@"CenterNewFriendTableCell" bundle:[NSBundle mainBundle]];
    [self.myTableView registerNib:nib forCellReuseIdentifier:newFriendReuse];
    
    [_myTableView release];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 64)];
    view.backgroundColor = DSRGBA(140, 140, 140, 0.2);
    [self.view addSubview:view];
    [view release];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(25, 30, 25, 25);
    [backButton setBackgroundImage:[UIImage imageNamed:@"camera_edit_cross"] forState:UIControlStateNormal];
    [self.view addSubview:backButton];
    [backButton addTarget:self action:@selector(backbuttonAction) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 50, 20, 100, 44)];
    title.text = @"新的朋友";
    title.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:title];
    [title release];
    
}

//返回按钮
- (void)backbuttonAction{
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}

#pragma mark 协议方法

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.friendNewArrayM.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CenterNewFriendTableCell *cell = [tableView dequeueReusableCellWithIdentifier:newFriendReuse];
    CenterNewFriendModel *model = [self.friendNewArrayM objectAtIndex:indexPath.row];
    cell.myModel = model;
    
    cell.myBlock = ^(BOOL isSuccess, NSString *userName){
        if (isSuccess) {
         AppDelegate *temp = [[UIApplication sharedApplication] delegate];
            [temp.buddy removeObjectForKey:userName];
        }
        [self.myTableView reloadData];
        
    };
    
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
